define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'out/index' + location.search,
                    add_url: 'out/add',
                    del_url: 'out/del',
                    multi_url: 'out/multi',
                    table: 'out',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'out_order_no', title: __('Out_order_no')},
                        {field: 'nickname', title: __('User_id')},
                        {
                            field: 'name',operate:false, title: '商品名称',formatter:function(value,row,index){
                               
                               
                                var goods_name = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    goods_name += row.good_json_text[i]['good_data']['sku']+'<br><br>';
                                }
                                return goods_name;

                            }
                        },
                        
                        {
                            field: 'good_json',operate:false, title: '客户名称',formatter:function(value,row,index){
                                var client = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    client += row.good_json_text[i]['client']+'<br><br>';
                                }
                                return client;
                            }
                        },

                        {
                            field: 'good_json',operate:false, title: __('Out_num'),formatter:function(value,row,index){
                                var out_num = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    out_num += row.good_json_text[i]['out_num']+'<br><br>';
                                }
                                return out_num;
                            }
                        },
                        {field: 'outtime', title: __('Outtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},

                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                       
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});